package com.taldh.mutlithread;

public class ThreadJoin {

    private static Object lock = new Object();

    public static void main(String[] args) {
        Thread threadA = new Thread(() -> {
            synchronized (lock) {
                System.out.println("t1 开始运行");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("t1 开始结束");
            }
        });

        Thread threadB = new Thread(() -> {
            synchronized (lock) {
                System.out.println("t2 开始运行");
                try {
                    threadA.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("t2 开始结束");
            }
        });

        threadA.start();
        threadB.start();
    }
}
